<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>libwebsockets: Socket adoption helpers</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="libwebsockets.org-logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libwebsockets
   </div>
   <div id="projectbrief">Lightweight C library for HTML5 websockets</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__sock-adopt.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Socket adoption helpers</div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gabe71b7462afb21c767bdc67334f305af"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN struct lws *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sock-adopt.html#gabe71b7462afb21c767bdc67334f305af">lws_adopt_socket</a> (struct lws_context *context, lws_sockfd_type accept_fd)</td></tr>
<tr class="separator:gabe71b7462afb21c767bdc67334f305af"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab2d045df0f81afe00891aaed312d552b"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN struct lws *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sock-adopt.html#gab2d045df0f81afe00891aaed312d552b">lws_adopt_socket_readbuf</a> (struct lws_context *context, lws_sockfd_type accept_fd, const char *readbuf, size_t len)</td></tr>
<tr class="separator:gab2d045df0f81afe00891aaed312d552b"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<h2>Socket adoption helpers</h2>
<p>When integrating with an external app with its own event loop, these can be used to accept connections from someone else's listening socket.</p>
<p>When using lws own event loop, these are not needed. </p>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="gabe71b7462afb21c767bdc67334f305af"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN struct lws* lws_adopt_socket </td>
          <td>(</td>
          <td class="paramtype">struct lws_context *&#160;</td>
          <td class="paramname"><em>context</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">lws_sockfd_type&#160;</td>
          <td class="paramname"><em>accept_fd</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__sock-adopt.html#gabe71b7462afb21c767bdc67334f305af">lws_adopt_socket()</a> - adopt foreign socket as if listen socket accepted it </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">context</td><td>lws context </td></tr>
    <tr><td class="paramname">accept_fd</td><td>fd of already-accepted socket to adopt</td></tr>
  </table>
  </dd>
</dl>
<p>Either returns new wsi bound to accept_fd, or closes accept_fd and returns NULL, having cleaned up any new wsi pieces.</p>
<p>LWS adopts the socket in http serving mode, it's ready to accept an upgrade to ws or just serve http. </p>

</div>
</div>
<a class="anchor" id="gab2d045df0f81afe00891aaed312d552b"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN struct lws* lws_adopt_socket_readbuf </td>
          <td>(</td>
          <td class="paramtype">struct lws_context *&#160;</td>
          <td class="paramname"><em>context</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">lws_sockfd_type&#160;</td>
          <td class="paramname"><em>accept_fd</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>readbuf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>len</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__sock-adopt.html#gab2d045df0f81afe00891aaed312d552b">lws_adopt_socket_readbuf()</a> - adopt foreign socket and first rx as if listen socket accepted it </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">context</td><td>lws context </td></tr>
    <tr><td class="paramname">accept_fd</td><td>fd of already-accepted socket to adopt </td></tr>
    <tr><td class="paramname">readbuf</td><td>NULL or pointer to data that must be drained before reading from accept_fd </td></tr>
    <tr><td class="paramname">len</td><td>The length of the data held at </td></tr>
    <tr><td class="paramname">readbuf</td><td>Either returns new wsi bound to accept_fd, or closes accept_fd and returns NULL, having cleaned up any new wsi pieces.</td></tr>
  </table>
  </dd>
</dl>
<p>LWS adopts the socket in http serving mode, it's ready to accept an upgrade to ws or just serve http.</p>
<p>If your external code did not already read from the socket, you can use <a class="el" href="group__sock-adopt.html#gabe71b7462afb21c767bdc67334f305af">lws_adopt_socket()</a> instead.</p>
<p>This api is guaranteed to use the data at </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">readbuf</td><td>first, before reading from the socket.</td></tr>
  </table>
  </dd>
</dl>
<p>readbuf is limited to the size of the ah rx buf, currently 2048 bytes. </p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
